package org.iteam.bank.signed.action;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.iteam.bank.mina.utils.ConfigLoader;
import org.iteam.web.struts.action.JsonServletAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("unchecked")
@Results({ @Result(type = "freemarker", name = "signed-error", location = "/WEB-INF/content/platform/signed-error.html"),
		@Result(type = "freemarker", name = "subscribe-error", location = "/WEB-INF/content/platform/subscribe-error.html") })
public class BaseAction extends JsonServletAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -401501358742133397L;
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	protected void init() {
		map.put("PC_URL", ConfigLoader.get("PC_URL"));
	}

	public boolean redirectURL(String URL) {
		try {
			response.sendRedirect(URL);
			return true;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return false;
	}

	public String signedError(String gotoURL, String errorMsg, String moudleName) {
		init();
		map.put("gotoURL", gotoURL);
		map.put("errorMsg", errorMsg);
		map.put("errorType", "error");
		map.put("moduleName", moudleName);
		return "signed-error";
	}

	public String signedSuccess(String gotoURL, String errorMsg, String moudleName) {
		init();
		map.put("gotoURL", gotoURL);
		map.put("errorMsg", errorMsg);
		map.put("errorType", "success");
		map.put("moduleName", moudleName);
		return "signed-error";
	}

	public String signedWarn(String gotoURL, String errorMsg, String moudleName) {
		init();
		map.put("gotoURL", gotoURL);
		map.put("errorMsg", errorMsg);
		map.put("errorType", "warn");
		map.put("moduleName", moudleName);
		return "signed-error";
	}

	public String subscribeError(String gotoURL, String errorMsg, String moudleName) {
		init();
		map.put("gotoURL", gotoURL);
		map.put("errorMsg", errorMsg);
		map.put("errorType", "error");
		map.put("moduleName", moudleName);
		return "subscribe-error";
	}

	public String subscribeSuccess(String gotoURL, String errorMsg, String moudleName) {
		init();
		map.put("gotoURL", gotoURL);
		map.put("errorMsg", errorMsg);
		map.put("errorType", "success");
		map.put("moduleName", moudleName);
		return "subscribe-error";
	}

	public String subscribeWarn(String gotoURL, String errorMsg, String moudleName) {
		init();
		map.put("gotoURL", gotoURL);
		map.put("errorMsg", errorMsg);
		map.put("errorType", "warn");
		map.put("moduleName", moudleName);
		return "subscribe-error";
	}
}
